package controller

import (
	"ez/apps/study/auto/controller"
	study "ez/apps/study/document"
	"ez/custom/baidu"
	"ez/custom/cc"
	"gitee.com/dreamwood/ez-go/ez"
)

type ReadWriteController struct {
	controller.ReadWriteAutoController
}

func init() {
	c := &ReadWriteController{}
	c.SetRouteParam("/study", "/admin", "ReadWrite")
	ez.CreateApi(c.AdminGet(), c.GetAction).SetRouterName("[study]读写_创建")
	ez.CreateApi(c.AdminList(), c.ListAction).SetRouterName("[study]读写_列表")
	ez.CreateApi(c.AdminSave(), c.SaveAction).SetRouterName("[study]读写_保存")
	ez.CreateApi(c.AdminCopy(), c.CopyAction).SetRouterName("[study]读写_复制")
	ez.CreateApi(c.AdminUpdate(), c.UpdateAction).SetRouterName("[study]读写_更新")
	ez.CreateApi(c.AdminChoice(), c.ChoiceAction).SetRouterName("[study]读写_选项")
	ez.CreateApi(c.AdminDelete(), c.DeleteAction).SetRouterName("[study]读写_删除")
	ez.CreateApi(c.AdminUnDelete(), c.UnDeleteAction).SetRouterName("[study]读写_恢复")
	ez.CreateApi(c.AdminDestroy(), c.DestroyAction).SetRouterName("[study]读写_销毁")
	ez.CreateApi(c.AdminUpdateMany(), c.UpdateManyAction).SetRouterName("[study]读写_更新_批量")
	ez.CreateApi(c.AdminDeleteMany(), c.DeleteManyAction).SetRouterName("[study]读写_删除_批量")
	ez.CreateApi(c.AdminDestroyMany(), c.DestroyManyAction).SetRouterName("[study]读写_销毁_批量")
	ez.CreateApi(c.AdminModelApi("tts"), c.TTSAction).SetRouterName("[study]读写_TTS")

}

// func (c ReadWriteController) AccessControl(session *ez.Session) { /* 在这里面重构 */ }
// func (c ReadWriteController) GetAction(session *ez.Session) { /* 在这里面重构 */ }
// func (c ReadWriteController) ListAction(session *ez.Session) { /* 在这里面重构 */ }
func (c ReadWriteController) TTSAction(session *ez.Session) {
	this := cc.New(session)
	find, e := study.NewReadWriteCrud().FindId(this.Get("id").IsInt64())
	if this.Try(e) {
		return
	}
	find.Mp3 = baidu.GetAndSaveTts(find.Read)
	if this.Try(find.Save()) {
		return
	}
	this.ReturnSuccess("OK", find)

}
